package com.zgkxzx.mvpbase.presenter;

import java.lang.ref.WeakReference;

/**
 * 创建者 zgkxzx
 * 日期   2017-04-01
 * 描述 BasePresenter 协调执行者基类
 */

public class BasePresenter<V> {


    protected WeakReference<V> mViewRef;

    /**
     * 关联view模型
     *
     * @param view
     */
    public void attachView(V view) {
        mViewRef = new WeakReference<V>(view);
    }


    /**
     * 取消关联view
     */
    public void detachView() {
        if (mViewRef != null) {
            mViewRef.clear();
            mViewRef = null;
        }
    }

    /**
     * 获取view
     *
     * @return
     */
    public V getView() {
        return mViewRef==null?null:mViewRef.get();
    }
}
